package com.xiaochong.tir.api.scheduled;

import com.alibaba.fastjson.JSON;
import com.xiaochong.service.common.config.redis.RedisServer;
import com.xiaochong.tir.api.config.ExecutorConfig;
import com.xiaochong.tir.api.service.walian.TokenIndexService;
import com.xiaochong.tir.api.util.ListSortUtil;
import com.xiaochong.tir.common.data.vo.walian.WalianDiagnosis;
import com.xiaochong.tir.common.util.RedisKeysUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: WangXing
 * @Description:挖链接口：组装货币诊断-曲线图和评语
 * @CreateDate: 2018/7/4 17:21
 */
@Component
public class TokenIndexScheduled {

    @Autowired
    private RedisServer redisServer;
    @Autowired
    private TokenIndexService tokenIndexService;
    @Async(ExecutorConfig.SCHEDULER_EXECUTOR_POOL)
    @Scheduled(cron="0 */5 * * * ?")
    public void setApiWdList(){
        List<WalianDiagnosis> wdList = tokenIndexService.getCurrencyAndComment();
        ListSortUtil sortUtil = new ListSortUtil();
        sortUtil.mySort(wdList,"rank","asc");
        if(null != wdList){
            redisServer.set(RedisKeysUtils.WLAPI_CURRENCY_DIAGNOSIS_GRAPHS_COMMENTS, JSON.toJSONString(wdList));
        }
    }
}
